//
//  RadioDetailsInfoViewController.m
//  aMoment
//
//  Created by dllo on 15/10/19.
//  Copyright © 2015年 LuckyHan. All rights reserved.
//

#import "RadioDetailsInfoViewController.h"
#import "AllHeaderFiles.h"

@interface RadioDetailsInfoViewController ()<BackgroundImageDelegate>
@property(nonatomic, retain)RadioDetailsInfoView *infoView;
@property(nonatomic, retain)RadioDetailsInfo *detailsInfo;
@property(nonatomic, retain)UIImageView *backImageView;
@property(nonatomic, retain)MBProgressHUD *progressView;
@end

@implementation RadioDetailsInfoViewController

- (void)dealloc
{
    [_infoView release];
    [_detailsInfo release];
    [_backImageView release];
    [_progressView release];
    [_listArray release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self getData];
    
    //block实现换歌
    void (^selectBlock)(NSString *) = ^(NSString *tingId) {
        _tingId = tingId;
        [self getData];
    };
    _infoView.block = selectBlock;
}

#pragma mark 获取数据
- (void)getData
{
    [NetworkRequest getDataWithURLString:@"http://api2.pianke.me/ting/info" BodyString:[NSString stringWithFormat:@"tingid=%@&client=2", _tingId] DataBlock:^(id data) {
        //移除加载中提示视图
        [_progressView removeFromSuperview];
        
        NSDictionary *dataDict = [(NSDictionary *)data objectForKey:@"data"];
        _detailsInfo = [[RadioDetailsInfo alloc] init];
        [_detailsInfo setValuesForKeysWithDictionary:dataDict];
        _infoView.index = _index;
        _infoView.listArray = _listArray;
        _infoView.detailsInfo = _detailsInfo;
    }];
}

- (void)loadView
{
    [super loadView];
    //背景图片
    self.backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -64, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _backImageView.contentMode = UIViewContentModeScaleAspectFill;
    _backImageView.clipsToBounds = YES;
    [self.view addSubview:_backImageView];
    [_backImageView release];
    
    //黑色背景效果
    UIImageView *blackImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -64, SCREEN_WIDTH, SCREEN_HEIGHT)];
    blackImageView.backgroundColor = [UIColor blackColor];
    blackImageView.alpha = .3;
    [self.view addSubview:blackImageView];
    [blackImageView release];
    
    self.infoView = [[RadioDetailsInfoView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    _infoView.delegate = self;
    [self.view addSubview:_infoView];
    [_infoView release];
    
    //创建加载中提示视图
    self.progressView = [LoadingProgress createViewWithSuperviewFrame:self.view.frame];
    [self.view addSubview:_progressView];
    [_progressView release];
}

#pragma mark 协议设置背景图片
- (void)passImage:(UIImage *)image
{
    _backImageView.image = [UIImage imageWithBlurImage:image intputRadius:30];
}

#pragma mark 视图即将出现
- (void)viewWillAppear:(BOOL)animated
{
    //改变播放按钮图片
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"rate"]) {
        _infoView.playImageView.image = [UIImage imageNamed:@"desk2_pause"];
    } else {
        _infoView.playImageView.image = [UIImage imageNamed:@"desk2_play"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
